//----------------------------------------------------------------------------------------------------------------------
// Copyright (c) 2012 James Whitworth
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//----------------------------------------------------------------------------------------------------------------------
#include "gmock/gmock.h"
#include "sqbind/sqbBind.h"
#include "../fixtures/SquirrelFixture.h"
#include "../mocks/autogen/MockFunction4.h"
//----------------------------------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------------------------------
// THIS FILE IS AUTO GENERATED DO NOT EDIT.
//----------------------------------------------------------------------------------------------------------------------

namespace autogen
{
//----------------------------------------------------------------------------------------------------------------------
typedef SquirrelFixture BindFunctionTest;

//----------------------------------------------------------------------------------------------------------------------
typedef SquirrelFixture BindClassFunctionTest;

//----------------------------------------------------------------------------------------------------------------------
typedef SquirrelFixture BindSingletonFunctionTest;

//----------------------------------------------------------------------------------------------------------------------
// Test4ParametersReturnVoid
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindFunctionTest, Test4ParametersReturnVoid)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  OtherBoundClass invalidParameter;
  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  EXPECT_CALL(mock, ClassVoidFunction4(parameter0, parameter1, parameter2, parameter3))
    .Times(2);

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  EXPECT_TRUE(sqb::Bind::BindFunction(m_vm, -1, &MockFunction4::VoidFunction4, _SC("VoidFunction4")));

  sq_pushstring(m_vm, _SC("Mock"), -1);
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_TRUE(sqb::Bind::BindFunction(m_vm, 3, &MockFunction4::VoidFunction4, _SC("VoidFunction4")));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_rawset(m_vm, -3));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &invalidParameter, _SC("invalidParameter")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  CompileAndSucceedCall("VoidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CompileAndSucceedCall("Mock.VoidFunction4(parameter0, parameter1, parameter2, parameter3)");

  CompileAndFailCall("VoidFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("VoidFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("VoidFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("VoidFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4ParametersReturnVoid
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindClassFunctionTest, Test4ParametersReturnVoid)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  OtherBoundClass invalidParameter;
  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  EXPECT_CALL(mock, ClassVoidFunction4(parameter0, parameter1, parameter2, parameter3))
    .Times(1);
  EXPECT_CALL(mock, ConstClassVoidFunction4(parameter0, parameter1, parameter2, parameter3))
    .Times(1);

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  // bind the mock class
  //
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_settypetag(m_vm, -1, sqb::ClassTypeTag<MockFunction4>::Get()));
  HSQOBJECT class_object;
  sq_getstackobj(m_vm, -1, &class_object);
  sqb::ClassTypeTag<MockFunction4>::Get()->SetClassObject(m_vm, class_object);
  EXPECT_TRUE(sqb::Bind::BindClassFunction<MockFunction4>(m_vm, -1, &MockFunction4::ClassVoidFunction4, _SC("ClassVoidFunction4")));
  EXPECT_TRUE(sqb::Bind::BindClassFunction<MockFunction4>(m_vm, 2, &MockFunction4::ConstClassVoidFunction4, _SC("ConstClassVoidFunction4")));
  sq_poptop(m_vm);

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, static_cast<MockFunction4 *>(&mock), _SC("mock")));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &invalidParameter, _SC("invalidParameter")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  CompileAndSucceedCall("mock.ClassVoidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CompileAndSucceedCall("mock.ConstClassVoidFunction4(parameter0, parameter1, parameter2, parameter3)");

  CompileAndFailCall("mock.ClassVoidFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassVoidFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("mock.ClassVoidFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassVoidFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("mock.ClassVoidFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassVoidFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("mock.ClassVoidFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassVoidFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4ParametersReturnVoid
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindSingletonFunctionTest, Test4ParametersReturnVoid)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  OtherBoundClass invalidParameter;
  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  EXPECT_CALL(mock, ClassVoidFunction4(parameter0, parameter1, parameter2, parameter3))
    .Times(1);
  EXPECT_CALL(mock, ConstClassVoidFunction4(parameter0, parameter1, parameter2, parameter3))
    .Times(1);

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  // bind the mock class
  //
  sq_pushstring(m_vm, _SC("Mock"), -1);
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_TRUE(sqb::Bind::BindSingletonFunction<MockFunction4>(m_vm, -1, &mock, &MockFunction4::ClassVoidFunction4, _SC("ClassVoidFunction4")));
  EXPECT_TRUE(sqb::Bind::BindSingletonFunction<MockFunction4>(m_vm, 1, &mock, &MockFunction4::ConstClassVoidFunction4, _SC("ConstClassVoidFunction4")));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_rawset(m_vm, -3));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &invalidParameter, _SC("invalidParameter")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  CompileAndSucceedCall("Mock.ClassVoidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CompileAndSucceedCall("ConstClassVoidFunction4(parameter0, parameter1, parameter2, parameter3)");

  CompileAndFailCall("Mock.ClassVoidFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassVoidFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Mock.ClassVoidFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassVoidFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Mock.ClassVoidFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassVoidFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Mock.ClassVoidFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassVoidFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4Parameters
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindFunctionTest, Test4Parameters)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  OtherBoundClass invalidParameter;
  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  BoundClass expected_result(0xffffffff);
  EXPECT_CALL(mock, ClassFunction4(parameter0, parameter1, parameter2, parameter3))
    .Times(2)
    .WillRepeatedly(::testing::Return(expected_result));

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  EXPECT_TRUE(sqb::Bind::BindFunction(m_vm, -1, &MockFunction4::Function4, _SC("Function4")));

  sq_pushstring(m_vm, _SC("Mock"), -1);
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_TRUE(sqb::Bind::BindFunction(m_vm, 3, &MockFunction4::Function4, _SC("Function4")));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_rawset(m_vm, -3));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &invalidParameter, _SC("invalidParameter")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  BoundClass actual_result = CompileAndCallReturnResult<BoundClass>("return Function4(parameter0, parameter1, parameter2, parameter3)");
  EXPECT_EQ(expected_result, actual_result);
  actual_result = CompileAndCallReturnResult<BoundClass>("return Mock.Function4(parameter0, parameter1, parameter2, parameter3)");
  EXPECT_EQ(expected_result, actual_result);

  CompileAndFailCall("Function4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Function4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Function4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Function4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4Parameters
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindClassFunctionTest, Test4Parameters)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  OtherBoundClass invalidParameter;
  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  BoundClass expected_result(0xffffffff);
  EXPECT_CALL(mock, ClassFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));
  EXPECT_CALL(mock, ConstClassFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  // bind the mock class
  //
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_settypetag(m_vm, -1, sqb::ClassTypeTag<MockFunction4>::Get()));
  HSQOBJECT class_object;
  sq_getstackobj(m_vm, -1, &class_object);
  sqb::ClassTypeTag<MockFunction4>::Get()->SetClassObject(m_vm, class_object);
  EXPECT_TRUE(sqb::Bind::BindClassFunction<MockFunction4>(m_vm, -1, &MockFunction4::ClassFunction4, _SC("ClassFunction4")));
  EXPECT_TRUE(sqb::Bind::BindClassFunction<MockFunction4>(m_vm, 2, &MockFunction4::ConstClassFunction4, _SC("ConstClassFunction4")));
  sq_poptop(m_vm);

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, static_cast<MockFunction4 *>(&mock), _SC("mock")));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &invalidParameter, _SC("invalidParameter")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  BoundClass actual_result = CompileAndCallReturnResult<BoundClass>("return mock.ClassFunction4(parameter0, parameter1, parameter2, parameter3)");
  EXPECT_EQ(expected_result, actual_result);
  actual_result = CompileAndCallReturnResult<BoundClass>("return mock.ConstClassFunction4(parameter0, parameter1, parameter2, parameter3)");
  EXPECT_EQ(expected_result, actual_result);

  CompileAndFailCall("mock.ClassFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("mock.ClassFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("mock.ClassFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("mock.ClassFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("mock.ConstClassFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4Parameters
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindSingletonFunctionTest, Test4Parameters)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  OtherBoundClass invalidParameter;
  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  BoundClass expected_result(0xffffffff);
  EXPECT_CALL(mock, ClassFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));
  EXPECT_CALL(mock, ConstClassFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  // bind the mock class
  //
  sq_pushstring(m_vm, _SC("Mock"), -1);
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_TRUE(sqb::Bind::BindSingletonFunction<MockFunction4>(m_vm, -1, &mock, &MockFunction4::ClassFunction4, _SC("ClassFunction4")));
  EXPECT_TRUE(sqb::Bind::BindSingletonFunction<MockFunction4>(m_vm, 1, &mock, &MockFunction4::ConstClassFunction4, _SC("ConstClassFunction4")));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_rawset(m_vm, -3));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &invalidParameter, _SC("invalidParameter")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  BoundClass actual_result = CompileAndCallReturnResult<BoundClass>("return Mock.ClassFunction4(parameter0, parameter1, parameter2, parameter3)");
  EXPECT_EQ(expected_result, actual_result);
  actual_result = CompileAndCallReturnResult<BoundClass>("return ConstClassFunction4(parameter0, parameter1, parameter2, parameter3)");
  EXPECT_EQ(expected_result, actual_result);

  CompileAndFailCall("Mock.ClassFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassFunction4(invalidParameter, parameter1, parameter2, parameter3)");
  CheckErrorString("parameter 1 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Mock.ClassFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassFunction4(parameter0, invalidParameter, parameter2, parameter3)");
  CheckErrorString("parameter 2 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Mock.ClassFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassFunction4(parameter0, parameter1, invalidParameter, parameter3)");
  CheckErrorString("parameter 3 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");

  CompileAndFailCall("Mock.ClassFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
  CompileAndFailCall("ConstClassFunction4(parameter0, parameter1, parameter2, invalidParameter)");
  CheckErrorString("parameter 4 has an invalid type 'OtherBoundClass' ; expected: 'BoundClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4ParametersReturnInvalid
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindFunctionTest, Test4ParametersReturnInvalid)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  InvalidStackUtilsClass expected_result;
  EXPECT_CALL(mock, ClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3))
    .Times(2)
    .WillRepeatedly(::testing::Return(expected_result));

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  EXPECT_TRUE(sqb::Bind::BindFunction(m_vm, -1, &MockFunction4::InvalidFunction4, _SC("InvalidFunction4")));

  sq_pushstring(m_vm, _SC("Mock"), -1);
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_TRUE(sqb::Bind::BindFunction(m_vm, 3, &MockFunction4::InvalidFunction4, _SC("InvalidFunction4")));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_rawset(m_vm, -3));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  CompileAndFailCall("InvalidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CheckErrorString("error returning object of type 'InvalidStackUtilsClass'");
  CompileAndFailCall("Mock.InvalidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CheckErrorString("error returning object of type 'InvalidStackUtilsClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4ParametersReturnInvalid
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindClassFunctionTest, Test4ParametersReturnInvalid)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  InvalidStackUtilsClass expected_result;
  EXPECT_CALL(mock, ClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));
  EXPECT_CALL(mock, ConstClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  // bind the mock class
  //
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_settypetag(m_vm, -1, sqb::ClassTypeTag<MockFunction4>::Get()));
  HSQOBJECT class_object;
  sq_getstackobj(m_vm, -1, &class_object);
  sqb::ClassTypeTag<MockFunction4>::Get()->SetClassObject(m_vm, class_object);
  EXPECT_TRUE(sqb::Bind::BindClassFunction<MockFunction4>(m_vm, -1, &MockFunction4::ClassInvalidFunction4, _SC("ClassInvalidFunction4")));
  EXPECT_TRUE(sqb::Bind::BindClassFunction<MockFunction4>(m_vm, 2, &MockFunction4::ConstClassInvalidFunction4, _SC("ConstClassInvalidFunction4")));
  sq_poptop(m_vm);

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, static_cast<MockFunction4 *>(&mock), _SC("mock")));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  CompileAndFailCall("mock.ClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CheckErrorString("error returning object of type 'InvalidStackUtilsClass'");
  CompileAndFailCall("mock.ConstClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CheckErrorString("error returning object of type 'InvalidStackUtilsClass'");
}

//----------------------------------------------------------------------------------------------------------------------
// Test4ParametersReturnInvalid
//----------------------------------------------------------------------------------------------------------------------
TEST_F(BindSingletonFunctionTest, Test4ParametersReturnInvalid)
{
  ::testing::StrictMock<MockFunction4> mock;
  MockFunction4::m_instance = &mock;

  sq_pushroottable(m_vm);
  sqb::Bind::BindClass<BoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("BoundClass"));
  sqb::Bind::BindClass<OtherBoundClass, sqb::NoBaseClass>(m_vm, -1, _SC("OtherBoundClass"));
  sq_poptop(m_vm);

  BoundClass parameter0(0);
  BoundClass parameter1(1);
  BoundClass parameter2(2);
  BoundClass parameter3(3);

  InvalidStackUtilsClass expected_result;
  EXPECT_CALL(mock, ClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));
  EXPECT_CALL(mock, ConstClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3))
    .WillOnce(::testing::Return(expected_result));

  // bind the objects required for calling the function
  //
  sq_pushroottable(m_vm);

  // bind the mock class
  //
  sq_pushstring(m_vm, _SC("Mock"), -1);
  EXPECT_SQ_SUCCEEDED(m_vm, sq_newclass(m_vm, SQFalse));
  EXPECT_TRUE(sqb::Bind::BindSingletonFunction<MockFunction4>(m_vm, -1, &mock, &MockFunction4::ClassInvalidFunction4, _SC("ClassInvalidFunction4")));
  EXPECT_TRUE(sqb::Bind::BindSingletonFunction<MockFunction4>(m_vm, 1, &mock, &MockFunction4::ConstClassInvalidFunction4, _SC("ConstClassInvalidFunction4")));
  EXPECT_SQ_SUCCEEDED(m_vm, sq_rawset(m_vm, -3));

  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter0, _SC("parameter0")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter1, _SC("parameter1")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter2, _SC("parameter2")));
  EXPECT_TRUE(sqb::Bind::BindVariable(m_vm, -1, &parameter3, _SC("parameter3")));
  sq_poptop(m_vm);

  CompileAndFailCall("Mock.ClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CheckErrorString("error returning object of type 'InvalidStackUtilsClass'");
  CompileAndFailCall("ConstClassInvalidFunction4(parameter0, parameter1, parameter2, parameter3)");
  CheckErrorString("error returning object of type 'InvalidStackUtilsClass'");
}

} // namespace autogen
